﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace CustomerService
{
    public class PageBase : Page
    {

        public string LoginName
        {
            get { return Context.User.Identity.Name.ToString(); }
        }

        #region JS事件

        /// <summary>
        /// 关闭页面
        /// </summary>
        protected void CloseWindow()
        {
            //this.ClientScript.RegisterStartupScript(this.GetType(), "closewindow", "window.close();", true);
            ScriptManager.RegisterStartupScript(this, GetType(), "closewindow", "window.close();", true);
        }

        /// <summary>
        /// 关闭页面
        /// </summary>
        protected void ReturnAndClose(string returnValue)
        {
            //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "closewindow", returnValue + "window.close();", true);
            ScriptManager.RegisterStartupScript(this, GetType(), "closewindow", returnValue + "window.close();", true);
        }

        /// <summary>
        /// 提示关闭返回
        /// </summary>
        protected void AlterCloseReturn(string msg, string returnValue)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "closewindow",
                                                "alert('" + msg + "');" + returnValue + "window.close();", true);
        }

        /// <summary>
        /// 弹出提示信息
        /// </summary>
        /// <param name="msg"></param>
        protected void AlertMsg(string msg)
        {
            //this.ClientScript.RegisterStartupScript(this.GetType(), "alertmsg", "alert('" + msg + "');", true);
            msg = msg.Replace("'", "\'");
            msg = msg.Replace(Environment.NewLine, "\\n");
            ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg", "alert(\"" + msg + "\");", true);
        }

        /// <summary>
        /// 弹出提示并跳转页面
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        protected void AlterAndRedirect(string msg, string url)
        {
            //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertmsg", "alert('" + msg + "');location.href='" + url + "';", true);
            ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg",
                                                "alert('" + msg + "');location.href='" + url + "';", true);
        }

        /// <summary>
        /// 跳转页面
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        protected void Redirect(string url)
        {
            //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertmsg", "alert('" + msg + "');location.href='" + url + "';", true);
            ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg",
                                                "location.href='" + url + "';", true);
        }

        /// <summary>
        /// 注册方法
        /// </summary>
        protected void RegisterMethod(string methodName)
        {
            //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "RegisMethod", methodName, true);
            ScriptManager.RegisterStartupScript(this, GetType(), "RegisMethod", methodName, true);
        }

        #endregion

    }
}